Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/share/public_paths/[...id].tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { join } from "path";6import NextHead from "next/head";78import basePath from "lib/base-path";9import getPublicPathInfo from "lib/share/get-public-path-info";10import shareURL from "lib/share/share-url";11import withCustomize from "lib/with-customize";12import { getPublicPathNames } from "lib/names/public-path";13import PublicPath, { PublicPathProps } from "components/path/path";1415import ogShareLogo from "public/logo/og-share-logo.png";1617export default (props: PublicPathProps) => (18<>19<PublicPath {...props} />20<NextHead>21<meta property="og:type" content="article"/>22<meta property="og:title" content={props.path}/>2324{props.description && (25<meta property="og:description" content={props.description}/>26)}27{props.ogUrl && (28<meta property="og:url" content={props.ogUrl}/>29)}30{props.ogImage && (31<meta property="og:image" content={props.ogImage}/>32)}33{props.created && (34<meta property="article:published_time" content={props.created}/>35)}36{props.last_edited && (37<meta property="article:modified_time" content={props.last_edited}/>38)}39</NextHead>40</>41);4243export async function getServerSideProps(context) {44const id = context.params.id[0];45const relativePath = context.params.id.slice(1).join("/");46try {47const names = await getPublicPathNames(id);48if (names != null) {49// redirect50let location = join(51basePath,52names.owner,53names.project,54names.public_path,55);56if (context.params.id.length > 1) {57location = join(58location,59"files",60context.params.id.slice(1).join("/"),61);62}63return { props: { redirect: location } };64}65const props: PublicPathProps = await getPublicPathInfo({66id,67relativePath,68req: context.req,69});7071const customize = await withCustomize({ context, props });7273if (customize?.props?.customize != null) {74// Add full URL for social media sharing75//76customize.props.ogUrl = `${customize.props.customize.siteURL}${shareURL(77id,78relativePath,79)}`;8081// Add image path for social media sharing82//83customize.props.ogImage = customize.props.customize.logoSquareURL ||84`${customize.props.customize.siteURL}${ogShareLogo.src}`;85}8687return customize;88} catch (_err) {89console.log(_err);90return { notFound: true };91}92}939495